#!/usr/bin/env bash
# shellcheck disable=SC2145,SC2124

function calc() {
    {
        BC_LINE_LENGTH=999 bc -l <<<"scale=100; ${@}" | sed 's/^\./0./;s/^-\./-0./'
    }
}

function abs() {
    {
        awk '{OFMT="%.100f"}{print abs($1)} function abs(x){return (x < 0)?-x:x}' <<<"${@}"
    }
}

function exp() {
    {
        awk '{OFMT="%.100f"}{print exp($1)}' <<<"${@}"
    }
}

function atan2() {
    {
        awk '{OFMT="%.100f"}{print atan2($1, $2)}' <<<"${@}"
    }
}

function radian2degree() {
    {
        pi=$(calc "4 * a(1)")
        readonly pi
        calc "${@} * (180 / ${pi})"
    }
}

function degree2radian() {
    {
        pi=$(calc "4 * a(1)")
        readonly pi
        calc "${@} * (${pi} / 180)"
    }
}
